package com.qing.springbootinit.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qing.qingapicommon.model.entity.User;
import com.qing.qingapicommon.service.InnerUserService;
import com.qing.springbootinit.common.ErrorCode;
import com.qing.springbootinit.exception.BusinessException;
import com.qing.springbootinit.mapper.UserMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

// * @author qingfengzy
//这里要注册为远程调用，因为是给网关的全局拦截器调用的
@DubboService
public class InnerUserServiceImpl implements InnerUserService {
//    先到入mapper
    @Resource
    private UserMapper userMapper;
    @Override
    public User getInvokeUser(String accessKey) {
//        肯定要先查找数据库，从数据库里拿到用户的信息
//        用ak 和 sk 来查找
       if(StringUtils.isAnyBlank(accessKey)){
           throw new BusinessException(ErrorCode.PARAMS_ERROR);
       }
//       然后用搜索工具来查找
        QueryWrapper<User> queryWrapper =new QueryWrapper<>();
       queryWrapper.eq("accessKey",accessKey);
//       queryWrapper.eq("secretKey",secretKey);
        return userMapper.selectOne(queryWrapper);
    }
}
